import axios from "axios";

const instance = axios.create({
  timeout: 30 * 1000
})

instance.interceptors.request.use(function (config) {
  // config.headers['user-agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36';
  // console.info(`[REQUEST] ${config.method.toUpperCase()} ${config.url}`);
  return config;
});

instance.interceptors.response.use(function (response) {
  // const config = response.config;
  // console.info(`[RESPONSE] ${config.method.toUpperCase()} ${config.url} ${response.status}-${response.statusText}`);
  return response;
}, function (error) {
  const config = error.config;
  console.error(`[RESPONSE ERROR] ${error.message} ${config?.url}`);
  return Promise.reject(new Error(error.message));
});

export default instance;
